<!--
 * @Author: xiemei
 * @Date: 2021-07-01 16:44:13
 * @LastEditors: xiemei
 * @LastEditTime: 2021-07-01 19:26:46
 * @FilePath: \vue-bilibili-v2\06-tabbar\src\components\tabbar\TabBarItem.vue
-->
<template>
    
  <div class="tab-bar-item" @click="itemClick">
    <!-- 添加一些属性需要在插槽外添加一个div标签，将这些属性添加到div标签上，以免被替换掉 -->
    <div v-if="!isActive">
      <slot name="item-icon"></slot>
    </div>
    <div v-else>
      <slot name="item-icon-active"></slot>
    </div>

    <div :style="activeStyle">
      <slot name="item-text"></slot>
    </div>
    <!-- <div v-bind:class={active:isActive}>
      <slot name="item-text"></slot>
    </div> -->
      
  </div>
</template>

<script>
export default {
  name: "TarBarItem",
  // 父传子
  props: {
    path: String,
    activeColor:{
      type:String,
      default:'#EA95A8'
    }
  },
  data() {
    return {
      // isActive:true
    };
  },
  computed: {
    // 当前点击一个 的图标及文字变为红色
    isActive() {
      return this.$route.path.indexOf(this.path) !== -1;
    },
    activeStyle(){
      return this.isActive ? {color:this.activeColor} : {}
    }
  },
  methods: {
    itemClick() {
      this.$router.replace(this.path);
    },
  },
};
</script>

<style>
.tab-bar-item {
  flex: 1;
  text-align: center;
  height: 49px; /* 常用的一个高度 */
  font-size: 14px;
}
.tab-bar-item img {
  height: 24px;
  width: 24px;
  margin-top: 3px;
  vertical-align: middle;
  margin-bottom: 2px;
}
/* .active{
  color: #EA95A8;
} */
</style>
